//
//  AFUser.m
//  AFChat
//
//  Created by Void on 2018/6/20.
//  Copyright © 2018年 afei. All rights reserved.
//

#import "AFUser.h"
#import "NSString+PinYin.h"

@implementation AFUser

- (void)setUserName:(NSString *)userName {
    if ([userName isEqualToString:_userName]) {
        return;
    }
    
    _userName = userName;
    if (self.remarkName.length == 0 && self.nikeName.length == 0 && self.userName.length > 0) {
        self.pinyin = userName.pinyin;
        self.pinyinInitial = userName.pinyinInitial;
    }
}

- (void)setNikeName:(NSString *)nikeName {
    if ([nikeName isEqualToString:_nikeName]) {
        return;
    }
    _nikeName = nikeName;
    if (self.remarkName.length == 0 && self.nikeName.length > 0) {
        self.pinyin = nikeName.pinyin;
        self.pinyinInitial = nikeName.pinyinInitial;
    }
}

- (void)setRemarkName:(NSString *)remarkName {
    if ([remarkName isEqualToString:_remarkName]) {
        return;
    }
    _remarkName = remarkName;
    if (_remarkName.length > 0) {
        self.pinyin = remarkName.pinyin;
        self.pinyinInitial = remarkName.pinyinInitial;
    }
}

#pragma mark - Getter
- (NSString *)showName {
    return self.remarkName.length > 0 ? self.remarkName : (self.nikeName.length > 0 ? self.nikeName : self.userName);
}

@end
